-
Notifications
You must be signed in to change notification settings - Fork 156
add validation for name and description for model model group and connector resources #3805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
||
if (modelName != null && !isSafeText(modelName)) { | ||
exception = addValidationError( | ||
"Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.)", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is different with MLUpdateConnectorRequest.java one. Should we keep them consistent ?
"Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.). Max length: 1000 characters.",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, in the next revision I kept it consistent.
|
||
if (modelName != null && !isSafeText(modelName)) { | ||
exception = addValidationError( | ||
"Model connector name can only contain letters, digits, spaces, underscores (_), hyphens (-), and dots (.). Max length: 1000 characters.", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see where validate Max length: 1000 characters."
, Is that built-in logic in isSafeText
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I removed that restriction from the regex. But then I forgot to remove that from the error message.
Initially I was thinking to provide 1000 characters restriction.
What do you think? Should we add such kind of restriction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore the comment, find that internal logic in isSafeText
String modelName = updateModelInput.getName(); | ||
String description = updateModelInput.getDescription(); | ||
|
||
if (modelName != null && !isSafeText(modelName)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar checking in multiple places ? Can we build some common util method ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I thought about that and felt too lazy to refactor 😄. But I fixed it in the second revision. Thanks for insisting on the highest standards!
0326043
to
d8eeede
Compare
@@ -60,6 +63,9 @@ public class StringUtils { | |||
+ " return input;" | |||
+ "\n }\n"; | |||
|
|||
// Regex allows letters, digits, spaces, hyphens, underscores, and dots. | |||
private static final String SAFE_INPUT_REGEX = "^[a-zA-Z0-9 _\\-\\.:,'()]+$"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious how we determined the regex is this a standard regex generally used? I believe we want to prevent <, >, ;, ", /, \, =
.
Since we are using this for description, maybe we need to allow !, @
etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very good question. I didn't find any generic standard for the description field. So I think I'll go forward with this regex pattern: "^[\\p{L}\\p{N}\\s.,!?():@\\-_'\"]*$"
that allows:
Unicode letters (\p{L})
Unicode numbers (\p{N})
Whitespace (\s)
Common punctuation (.,!?():@)
Hyphen (\-)
Underscore (_)
Single and double quotes ('")
Restricts dangerous characters like:
< and > (prevents HTML/XML tags)
/ and \ (prevents path traversal)
& (prevents HTML entities)
- (prevents some SQL injection patterns)
= (prevents some query string manipulations)
; (prevents command injection)
Please let me know what do you guys think. I'm open to suggestion as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, allowing unicode makes a lot of sense. I think this regex is good. The same regex will apply for name field as well right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
…nector resources Signed-off-by: Dhrubo Saha <[email protected]>
…undnancy Signed-off-by: Dhrubo Saha <[email protected]>
Signed-off-by: Dhrubo Saha <[email protected]>
Signed-off-by: Dhrubo Saha <[email protected]>
Signed-off-by: Dhrubo Saha <[email protected]>
ec8b889
to
e33b553
Compare
Signed-off-by: Dhrubo Saha <[email protected]>
Signed-off-by: Dhrubo Saha <[email protected]>
add validation for name and description for model model group and connector resources
Description
resolved #3639
Integ test will fail as code coverages is failing for previously merged PR.
Related Issues
Resolves #[Issue number to be closed when this PR is merged]
Check List
--signoff
.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.